package com.gxa.j259.springcloud.f.hystrix.config;

import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author thinknovo
 * @version 1.0
 */
@Configuration
public class HystrixConfig {

    @Bean
    public HystrixCommandExecutionHook getHystrixCommandExecutionHook() {
        System.out.println("HystrixConfig---------------getHystrixCommandExecutionHook");
        HystrixHook hystrixHook = new HystrixHook();
        // 注册之前，必须重置，否则启动会提示注册失败，已经存在默认策略
        HystrixPlugins.reset();
        // 注册绑定钩子函数
        HystrixPlugins.getInstance().registerCommandExecutionHook(hystrixHook);
        return hystrixHook;
    }
}
